using System;
using System.Collections.Generic;
using System.Text;

using QLTDK.DataAccess.Interfaces.Base;

using Spring.Transaction;
using Spring.Transaction.Support;

namespace QLTDK.DataAccess.Base
{
    /// <summary>
    /// This has to implement <see cref="IDbContext" />, but there's no reason for it to be 
    /// recreated more than once.  Therefore, it shoutld be setup as a threadsafe singleton.
    /// </summary>
    public class DbContext : IDbContext
    {
        private IPlatformTransactionManager TransactionManager;

        public DbContext(IPlatformTransactionManager transactionManager)
        {
            this.TransactionManager = transactionManager;
        }

        /// <summary>
        /// This isn't specific to any one DAO and flushes everything that has been 
        /// changed since the last commit.
        /// </summary>
        public void CommitChanges()
        {
            
        }

        public void BeginTransaction()
        {
            ITransactionDefinition def = new DefaultTransactionDefinition();
            ITransactionStatus transactionStatus = TransactionManager.GetTransaction(def);
        }

        public void CommitTransaction()
        {
            ITransactionStatus transactionStatus = TransactionManager.GetTransaction(null);
            TransactionManager.Commit(transactionStatus);
        }

        public void RollbackTransaction()
        {
            ITransactionStatus transactionStatus = TransactionManager.GetTransaction(null);
            TransactionManager.Rollback(transactionStatus);
        }

    }
}

